package com.zxw.user.domain.entity;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zxw.common.core.base.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 *
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-02-27
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("ec_user_role")
public class UserRole extends BaseEntity {

    private static final long serialVersionUID = 1L;

    private Long userId;

    private Long roleId;

    public UserRole() {
    }

    public UserRole(User user) {
        super.setCreateTime(user.getCreateTime());
        super.setCompanyId(user.getCompanyId());
        super.setCreateUserAccount(user.getCreateUserAccount());
        super.setCreateUserId(user.getCreateUserId());
        super.setLastUpdateTime(user.getLastUpdateTime());
        super.setLastUpdateUserAccount(user.getLastUpdateUserAccount());
        super.setLastUpdateUserId(user.getLastUpdateUserId());
        this.userId = user.getId();
    }

    public UserRole(Long userId, Long companyId, Long createUserId, String createUserAccount, Long roleId) {
        super.setCreateTime(LocalDateTime.now());
        super.setCompanyId(companyId);
        super.setCreateUserId(createUserId);
        super.setCreateUserAccount(createUserAccount);
        super.setLastUpdateTime(LocalDateTime.now());
        super.setLastUpdateUserAccount(createUserAccount);
        super.setLastUpdateUserId(createUserId);
        this.userId = userId;
        this.roleId = roleId;
    }

    public UserRole(JSONObject jsonObject, Long userId, Long roleId) {
        super(jsonObject);
        this.userId = userId;
        this.roleId = roleId;
    }
}
